package com.yand.frame.utils;



import com.yand.frame.common.Result;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Component;

/**
 * 登录的工具类
 */
@Component
public class ActivityUtil {

    public Result doLogin(String name, String password){
        Result result = new Result(0);
        try{
            Subject subject = SecurityUtils.getSubject();
            UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(name,password);
            subject.login(usernamePasswordToken);
        }catch(IncorrectCredentialsException e){
            //用户名密码错误
            result.setCode(1001);
            result.setMessage("用户名或密码错误");
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

}
